using Brick;
using DG.Tweening;
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts.GDK
{
	public class gdk_utils
	{
		public static List<Vector3> BesselPath(Vector3 _pos1, Vector3 _pos2, Vector3 _pos3, Vector3 _pos4)
		{
			List<Vector3> list = new List<Vector3>();
			for (int i = 0; i < 200; i++)
			{
				Vector3 a = Vector3.Lerp(_pos1, _pos2, (float)i / 100f);
				Vector3 vector = Vector3.Lerp(_pos2, _pos3, (float)i / 100f);
				Vector3 b = Vector3.Lerp(_pos3, _pos4, (float)i / 100f);
				Vector3 a2 = Vector3.Lerp(a, vector, (float)i / 100f);
				Vector3 b2 = Vector3.Lerp(vector, b, (float)i / 100f);
				Vector3 item = Vector3.Lerp(a2, b2, (float)i / 100f);
				list.Add(item);
			}
			return list;
		}

		public static List<Vector3> ToPathList(Vector3 startPos, Vector3 endPos, float resolution = 10f)
		{
			List<Vector3> list = new List<Vector3>();
			list.Add(startPos);
			list.Add(new Vector3((startPos.x + endPos.x) / 2f + resolution, (startPos.y + endPos.y) / 2f + resolution, (startPos.z + endPos.z) / 2f));
			list.Add(endPos);
			return list;
		}

		public static long GetTimeStamp(bool isMS = false)
		{
			TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
			if (isMS)
			{
				return Convert.ToInt64(timeSpan.TotalMilliseconds);
			}
			return Convert.ToInt64(timeSpan.TotalSeconds);
		}

		public static string GetMD5(string strToEncrypt)
		{
			byte[] bytes = Encoding.UTF8.GetBytes(strToEncrypt);
			MD5 mD = MD5.Create();
			byte[] array = mD.ComputeHash(bytes);
			string text = string.Empty;
			for (int i = 0; i < array.Length; i++)
			{
				text += Convert.ToString(array[i], 16).PadLeft(2, '0');
			}
			return text.PadLeft(32, '0');
		}

		public static List<T> copyList<T>(List<T> list)
		{
			List<T> _list = (List<T>)new List<T>();
			list.ForEach(delegate(T i)
			{
				((List<T>)_list).Add(i);
			});
			return (List<T>)_list;
		}

		public static void removeAllChildren(Transform transform)
		{
			int childCount = transform.childCount;
			for (int i = 0; i < childCount; i++)
			{
				UnityEngine.Object.Destroy(transform.GetChild(i).gameObject);
			}
		}

		public static Transform FindChild(Transform trans, string goName)
		{
			Transform transform = trans.Find(goName);
			if (transform != null)
			{
				return transform;
			}
			Transform transform2 = null;
			for (int i = 0; i < trans.childCount; i++)
			{
				transform = trans.GetChild(i);
				transform2 = FindChild(transform, goName);
				if (transform2 != null)
				{
					return transform2;
				}
			}
			return null;
		}

		public static Text NewText()
		{
			GameObject gameObject = new GameObject("Text");
			gameObject.name = "Text";
			RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
			Text text = gameObject.AddComponent<Text>();
			rectTransform.sizeDelta = new Vector2(100f, 100f);
			rectTransform.localPosition = Vector3.zero;
			rectTransform.localScale = Vector3.one;
			rectTransform.anchoredPosition = new Vector2(0f, 0f);
			text.font = Font.CreateDynamicFontFromOSFont("Arial", 14);
			text.fontStyle = FontStyle.Normal;
			text.fontSize = 50;
			text.lineSpacing = 1f;
			text.color = Color.red;
			text.alignByGeometry = false;
			text.horizontalOverflow = HorizontalWrapMode.Wrap;
			text.verticalOverflow = VerticalWrapMode.Truncate;
			text.supportRichText = true;
			text.resizeTextForBestFit = false;
			text.alignment = TextAnchor.UpperCenter;
			text.alignment = TextAnchor.MiddleCenter;
			ContentSizeFitter contentSizeFitter = gameObject.AddComponent<ContentSizeFitter>();
			contentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
			contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
			return text;
		}

		public static AnimationClip GetAnimationClipByName(string name, Animator animator)
		{
			AnimationClip[] animationClips = animator.runtimeAnimatorController.animationClips;
			AnimationClip[] array = animationClips;
			foreach (AnimationClip animationClip in array)
			{
				if (animationClip.name.Equals(name))
				{
					return animationClip;
				}
			}
			return null;
		}

		public static Image NewImage()
		{
			GameObject gameObject = new GameObject("Image");
			RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
			Image result = gameObject.AddComponent<Image>();
			rectTransform.sizeDelta = new Vector2(100f, 100f);
			rectTransform.localPosition = Vector3.zero;
			rectTransform.localScale = Vector3.one;
			rectTransform.anchoredPosition = new Vector2(0f, 0f);
			return result;
		}

		public static RectTransform NewButton(GameObject parent = null)
		{
			GameObject gameObject = new GameObject("Button");
			RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
			if ((bool)parent)
			{
				rectTransform.SetParent(parent.transform, worldPositionStays: true);
			}
			Image image = gameObject.AddComponent<Image>();
			gameObject.AddComponent<Button>();
			rectTransform.sizeDelta = new Vector2(100f, 100f);
			rectTransform.localPosition = Vector3.zero;
			rectTransform.localScale = Vector3.one;
			rectTransform.anchoredPosition = new Vector2(0f, 0f);
			image.color = new Color(0f, 0f, 0f, 0f);
			return rectTransform;
		}

		public static RectTransform NewPlane(GameObject parent, string name)
		{
			GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
			RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
			rectTransform.position = new Vector2(0f, 0f);
			rectTransform.gameObject.name = name;
			rectTransform.SetParent(parent.transform);
			rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0f, 0f);
			rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0f, 0f);
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			rectTransform.localScale = Vector3.one;
			return rectTransform;
		}

		public static Vector2 getSceneSize()
		{
			Camera main = Camera.main;
			Vector3 position = Camera.main.transform.position;
			Vector3 vector = main.ViewportToWorldPoint(new Vector3(1f, 1f, Mathf.Abs(position.z)));
			Vector3 position2 = Camera.main.transform.position;
			float x = position2.x;
			float x2 = vector.x;
			Vector3 position3 = Camera.main.transform.position;
			float num = x - (x2 - position3.x);
			float x3 = vector.x;
			float y = vector.y;
			Vector3 position4 = Camera.main.transform.position;
			float y2 = position4.y;
			float y3 = vector.y;
			Vector3 position5 = Camera.main.transform.position;
			float num2 = y2 - (y3 - position5.y);
			float x4 = x3 - num;
			float y4 = y - num2;
			return new Vector2(x4, y4);
		}

		public static string[] Split(string cell, string key)
		{
			return Regex.Split(cell, key, RegexOptions.IgnoreCase);
		}

		public static void ForeachDictionary<T>(Dictionary<string, T> dictionary, Action action)
		{
		}

		public static void FideIn(GameObject gameObject, float time)
		{
			_FideIn(gameObject, time, delegate
			{
			});
		}

		public static void FideIn(GameObject gameObject, float time, Action action)
		{
			_FideIn(gameObject, time, action);
		}

		private static void _FideIn(GameObject gameObject, float time, Action action)
		{
			CanvasGroup canvasGroup = gameObject.GetComponent<CanvasGroup>();
			if (canvasGroup == null)
			{
				canvasGroup = gameObject.AddComponent<CanvasGroup>();
			}
			canvasGroup.alpha = 0f;
			DOTween.To(() => 0f, delegate(float x)
			{
				canvasGroup.alpha = x;
			}, 1f, time).OnComplete(delegate
			{
				action();
			});
		}

		public static void FideOut(GameObject gameObject, float time)
		{
			_FideOut(gameObject, time, delegate
			{
			});
		}

		public static void FideOut(GameObject gameObject, float time, Action action)
		{
			_FideOut(gameObject, time, action);
		}

		public static void _FideOut(GameObject gameObject, float time, Action action)
		{
			UnityEngine.Debug.Log("canvasGroup:");
			UnityEngine.Debug.Log(gameObject.name);
			CanvasGroup canvasGroup = gameObject.GetComponent<CanvasGroup>();
			if (canvasGroup == null)
			{
				canvasGroup = gameObject.AddComponent<CanvasGroup>();
			}
			canvasGroup.alpha = 1f;
			DOTween.To(() => 1f, delegate(float x)
			{
				canvasGroup.alpha = x;
			}, 0f, time).OnComplete(delegate
			{
				action();
			});
		}

		public static int Random(int minNum, int maxNum)
		{
			System.Random random = new System.Random();
			return random.Next(minNum, maxNum);
		}

		public static TimeModel getTimeModel()
		{
			TimeModel timeModel = new TimeModel();
			DateTime now = DateTime.Now;
			timeModel.Year = now.Year.ToString();
			timeModel.Month = now.Month.ToString();
			timeModel.DayOfWeek = now.DayOfWeek.ToString();
			timeModel.DayOfYear = now.DayOfYear.ToString();
			timeModel.Hour = now.Hour.ToString();
			timeModel.Minute = now.Minute.ToString();
			timeModel.Second = now.Second.ToString();
			return timeModel;
		}

		public static bool getTimeModelIsCurDay(TimeModel timeModel)
		{
			TimeModel timeModel2 = getTimeModel();
			return timeModel2.Year == timeModel.Year && timeModel2.Month == timeModel.Month && timeModel2.Month == timeModel.Month && timeModel2.DayOfWeek == timeModel.DayOfWeek && timeModel2.DayOfYear == timeModel.DayOfYear;
		}

		public static float getMagnitude2D(Vector3 pos1, Vector3 pos2)
		{
			Vector3 b = new Vector3(pos2.x, pos2.y, pos1.z);
			return (pos1 - b).magnitude;
		}

		public static List<Vector3> getMovePath(Vector3 startPos, Vector3 endPos)
		{
			Vector3 vector = startPos - endPos;
			float magnitude2D = getMagnitude2D(startPos, endPos);
			Vector3 pos = startPos;
			Vector3 pos2 = new Vector3(pos.x + vector.x, startPos.y, startPos.z);
			return BesselPath(_pos3: new Vector3(pos2.x + vector.x * 1.5f, pos2.y - magnitude2D / 1.5f, startPos.z), _pos1: pos, _pos2: pos2, _pos4: endPos);
		}

		public static Vector3 getRandomPos2D(Vector3 pos, int offset)
		{
			offset = Math.Abs(offset);
			int num = Random(-offset, offset);
			int num2 = Random(-offset, offset);
			return new Vector3(pos.x + (float)num, pos.y + (float)num2, pos.z);
		}
	}
}
